# _*_conding:cp-1252-*-
# 教育机构：银杰教育
# 讲师：李伟
# 开发时间：2025/8/22 下午11:49
import requests
import config

class UploadAPI:
    def __init__(self):
        self.url = config.BASE_URL1 + "/p/file/upload"

    def upload(self,header,files):
        return requests.request(url=self.url,method="post",headers=header,files=files)

if __name__ == '__main__':
    from tools.handle_path import photo
    token = "bearerec1cf11d-0e5d-427b-836a-3a1f3478e20c"
    header = {"Authorization":token}
    with open(photo,"rb") as f:
        #二进制文件（图片、zip\exe） 使用"rb"。
        # 文本模式：r   文本模式非utf-8
        file =f.read()
        # print(file)
    # 写法一：
    files = {"file":file}
    # 写法二：
    # files = {"file":open(photo,"rb")}
    try:
        data = UploadAPI().upload(header=header,files=files)
        # 开始打印日志
        # 响应状态码是：
        print(data.status_code)
        # 响应文本是：
        print(data.text)
        # json解析是否成功
        try:
            print(data.json())
        except Exception as e:
            print(f"json解析失败：{e}")
            raise e

    except Exception as e:
        print(f"响应失败:{e}")
        raise e

